<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Click'N'Gage - Browse Questions</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" href="css/style.css" type="text/css" />
    </h:head>
    <h:body>
        <div id="container">
            <div id="wrapper">
                <div id="top">
                    <ui:include src="WEB-INF/includes/login.xhtml"/>
                </div>

                <ui:include src="WEB-INF/includes/navigation.xhtml"/>

                <div id="header">
                    <ui:include src="WEB-INF/includes/header.xhtml"/>
                </div>
                <div id="content">
                    <h1>Browse Questions</h1>
                    <h:form>
                        <h:panelGrid columns="3">
                            <label>Course:</label>
                            <h:selectOneMenu value="#{questionBrowserManagedBean.courseID}">
                                <f:selectItems value="#{questionBrowserManagedBean.coursesTaught}"
                                               var="course"
                                               itemLabel="#{course.name} (#{course.code})"
                                               itemValue="#{course.id}"/>
                            </h:selectOneMenu>
                            <h:commandButton value="Get Questions" action="#{questionBrowserManagedBean.getQuestionsActionHandler}">
                                <!--<f:ajax render="@form" execute="@form"/>-->
                            </h:commandButton>

                            <h:outputText value="Filter by tag:" rendered="#{questionBrowserManagedBean.courseID != 0}"/>
                            <h:selectOneMenu value="#{questionBrowserManagedBean.tagID}" rendered="#{questionBrowserManagedBean.courseID != 0}">
                                <f:selectItems value="#{questionBrowserManagedBean.tagsForCourse}"
                                               var="tag"
                                               itemLabel="#{tag.name}"
                                               itemValue="#{tag.id}"/>
                            </h:selectOneMenu>
                            <h:commandButton value="Filter" action="#{questionBrowserManagedBean.tagFilterActionHandler}" rendered="#{questionBrowserManagedBean.courseID != 0}">
                                <!--<f:ajax render="@form" execute="@form"/>-->
                            </h:commandButton>
                        </h:panelGrid>
                        <h:panelGrid columns="1">
                            <h:outputText value="Questions:" rendered="#{questionBrowserManagedBean.courseID != 0}"/>
                            <h:dataTable border="0" rendered="#{questionBrowserManagedBean.courseID != 0}" value="#{questionBrowserManagedBean.questionsForCourse}" var="question">
                                <h:column>
                                    <f:facet name="header">
                                        ID
                                    </f:facet>
                                    <h:commandLink value="Question #{question.id}" action="question">
                                        <f:setPropertyActionListener target="#{questionDetailsManagedBean.questionID}" value="#{question.id}" />
                                    </h:commandLink>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        Question Text
                                    </f:facet>
                                    <h:outputText value="#{question.question}" />
                                </h:column>
                                <h:column>
                                    <h:commandLink value="Issue" action="#{questionBrowserManagedBean.issueQuestionActionHandler}">
                                        <f:setPropertyActionListener target="#{questionBrowserManagedBean.questionID}" value="#{question.id}"/>
                                    </h:commandLink>
                                </h:column>
                            </h:dataTable>
                            <br /><br />
                            <h:outputText value="Generated question code: #{questionBrowserManagedBean.issueCode}" style="color: red" rendered="#{questionBrowserManagedBean.issueCode != null}"/>
                        </h:panelGrid>
                        <h:messages styleClass="error" />
                        <h:outputText value="#{questionBrowserManagedBean.errorMessage}" styleClass="error" rendered="#{questionBrowserManagedBean.errorMessage != null}"/>
                    </h:form>
                </div>
                <div id="sidebar">
                    <h2>Quick Links</h2>
                    <ui:include src="WEB-INF/includes/quicklinks.xhtml"/>
                    <h2>Downloads</h2>
                    <ui:include src="WEB-INF/includes/download.xhtml"/>
                    <h2>Advertisments</h2>
                    <ui:include src="WEB-INF/includes/adsense.xhtml"/>
                </div>
                <div id="footer">
                    <ui:include src="WEB-INF/includes/footer.xhtml"/>
                </div>
            </div>
        </div>
    </h:body>
</html>